package com.ljxy.score.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ljxy.score.common.Result;
import com.ljxy.score.entity.domain.mystudent;
import com.ljxy.score.entity.domain.myteacher;
import com.ljxy.score.service.myteacherService;
import com.ljxy.score.mapper.myteacherMapper;
import com.ljxy.score.util.MD5Util;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @author 86189
 * @description 针对表【myteacher】的数据库操作Service实现
 * @createDate 2022-12-19 16:56:01
 */
@Service
public class myteacherServiceImpl extends ServiceImpl<myteacherMapper, myteacher>
        implements myteacherService {

    @Override
    public Result<?> register(String phone, String password) {
        if (StringUtils.isAnyBlank(phone, password)) {
            return Result.error("500", "参数错误");
        }
        //1.进行处理
        myteacher myteacher = new myteacher();
        myteacher.setPhone(phone);
        //进行加密处理
        String passwordEncry = MD5Util.string2MD5(password);
        myteacher.setPassword(passwordEncry);
        boolean isSuccess = this.save(myteacher);
        if (!isSuccess) {
            return Result.error("500", "插入数据库失败");
        }
        return Result.success("200");
    }

    /**
     * 实现登陆的教师用户注册功能
     * @param  phone
     * @param  password
     * @return count
     */
    @Override
    public Result<?> login(String phone, String password) {
        if (StringUtils.isAnyBlank(phone, password)) {
            return Result.error("500", "参数为null");
        }
        QueryWrapper<myteacher> queryWrapper = new QueryWrapper<>();
        String passwordEncrypt = MD5Util.string2MD5(password);
        queryWrapper.eq("phone", phone).eq("password", passwordEncrypt);
        int count = this.count(queryWrapper);
        if (count == 0) {
            return Result.error("500", "");
        }
        return Result.success(count);
    }
}




